package ui.components.renderlist
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.utils.getQualifiedClassName;
	
	import utils.ColorUtil;
	import utils.IClear;
	import utils.group.ISelectGroupItem;
	
    public class AbstractRenderer extends Sprite implements ISelectGroupItem, IClear
    {
        protected var _listVO:AbstractRendererVo;
        protected var _selectedCallback:Function;
        protected var _bg:Sprite;
        protected var _groupName:String;
        protected var _selected:Boolean = false;

        public function get selected():Boolean
        {
            return _selected;
        }
        public function set selected(value:Boolean):void
        {
            _selected = value;
            if (value)
            {
                ColorUtil.highLight(this);
                ColorUtil.addColorRing(_bg);
            } else {
                ColorUtil.deHighLight(this);
                ColorUtil.removeColorRing(_bg);
            }
            if (_selectedCallback != null)
            {
                _selectedCallback(this);
            }
        }
        public function get selectedCallback():Function
        {
            return _selectedCallback;
        }
        public function set selectedCallback(value:Function):void
        {
            _selectedCallback = value;
        }
        public function get selectable():Boolean
        {
            return true;
        }
        public function get groupName():String
        {
            return _groupName;
        }
        public function set groupName(value:String):void
        {
            _groupName = value;
        }
        public function get value():AbstractRendererVo
        {
            return _listVO;
        }
        public function get valueTypeName():String
        {
            return getQualifiedClassName(_listVO.rendererClass);
        }

        public function AbstractRenderer()
        {
            init();
        }

        protected function init():void
        {
            createBg();
            createView();
            initTab();
            addEvent();
        }
        protected function createBg():void
        {
            _bg = new Sprite();
            addChild(_bg);
        }
        protected function createView():void
        {
            
        }
        protected function initTab():void
        {
            this.tabEnabled = false;
        }
        protected function addEvent():void
        {
            this.addEventListener(MouseEvent.CLICK, clickHandler);
            this.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
            this.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
        }
        protected function mouseOverHandler(event:MouseEvent):void
        {
            
        }
        protected function mouseOutHandler(event:MouseEvent):void
        {
        	
        }
        protected function clickHandler(event:MouseEvent):void
        {
            if (_listVO.selectable)
            {
                selectResponse();
            }
        }
        protected function updateView():void
        {
            
        }
        protected function selectResponse():void
        {
            this.selected = true;
        }

        public function update(listVo:AbstractRendererVo):void
        {
            _listVO = listVo;
            this.buttonMode = listVo.selectable;
            if (listVo != null)
            {
                updateView();
            }
        }
        public function clear():void
        {
            this.selected = false;
        }
    }
}
